<template>
  <div class="smartRegistration">
    <goBack title="智能报考"></goBack>
    <div
      @touchmove.prevent
      @mousewheel.prevent
      @click="goToRecord"
      class="smartRegistration-record"
    >
      历史记录
    </div>
    <div class="smartRegistration-title">高帮帮圆梦大学</div>
    <div class="smartRegistration-subtitle">展人生画卷 划未来蓝图</div>
    <!-- 选择地区/年份 -->
    <div class="smartRegistration-wrap-title">
      <span></span>学业水平考试成绩：
    </div>
    <div
      class="smartRegistration-wrap"
      v-for="(item, index1) in smartRegistration"
      :key="item"
    >
      <div class="smartRegistration-wrap-item">
        <div class="smartRegistration-wrap-item-left">
          <img class="img" :src="smartRegistrationBg" />
          <div class="title">{{ item.title }}</div>
          <div class="subtitle">{{ item.enTitle }}</div>
        </div>
        <div class="smartRegistration-wrap-item-right">
          <img :src="smartRegistrationItem" />
          <div class="content-wrap">
            <div
              @click="changeOptions(index1, project)"
              v-for="project in item.options"
              :key="project"
              class="content"
              :class="{ active: item.chooseOption == project }"
            >
              {{ project }}
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="smartRegistration-wrap-title">
      <span></span>选考科目（七选三)：
    </div>
    <div class="smartRegistration-tects">
      <div
        v-for="item in projects"
        :key="item"
        :class="{ active: !!item.active }"
        class="smartRegistration-tects-items"
        @click="changeProject(item.name)"
      >
        {{ item.name }}
      </div>
    </div>
    <div class="btn" @click="submit">确定</div>
    <van-popup :show="show">
      <div class="joinNow">
        <div class="close" @click="closeModal"></div>
        <div class="join">
          <span>
            尊敬的用户，欢迎您使用高帮帮三位一体高校智能推荐系统，使用前请先登录
          </span>
          <span>
            1，请您在页面选择真实学业水平考试成绩和高考选考科目，系统将自动为您推荐符合报考条件的高校。
          </span>
          <span>
            2，若想深入了解各高校的招生政策，专业等，可点击联系客服进行一对一进行咨询。
          </span>
          <span>
            3，特别申明：本智能推荐系统针对浙江三位一体高校推荐仅作为参考作用。
          </span>
          <div class="btn" @click="begin">立即开始</div>
        </div>
      </div>
    </van-popup>
  </div>
</template>

<script setup>
import { useRoute } from 'vue-router';
import { ref, reactive, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import { getIntelligent } from '../../api/apiList/homePage.js';
import smartRegistrationBg from '../../assets/images/smartRegistration-bg.jpg';
import smartRegistrationItem from '../../assets/images/smartRegistration-item.jpg';
import goBack from '../../components/goBack.vue';
const projects = reactive([
  {
    name: '政治',
    active: false
  },
  {
    name: '地理',
    active: false
  },
  {
    name: '历史',
    active: false
  },
  {
    name: '生物',
    active: false
  },
  {
    name: '物理',
    active: false
  },
  {
    name: '化学',
    active: false
  },
  {
    name: '技术',
    active: false
  }
]);
const smartRegistration = reactive([
  {
    title: '语文',
    enTitle: 'Chinese achievements',
    options: ['A', 'B', 'C', 'D', 'E'],
    subTitle: 'language',
    chooseOption: ''
  },
  {
    title: '数学',
    enTitle: 'Math scores',
    options: ['A', 'B', 'C', 'D', 'E'],
    subTitle: 'math',
    chooseOption: ''
  },
  {
    title: '英语',
    enTitle: 'English score',
    options: ['A', 'B', 'C', 'D', 'E'],
    subTitle: 'english',
    chooseOption: ''
  },
  {
    title: '政治',
    enTitle: 'Political achievemen',
    options: ['A', 'B', 'C', 'D', 'E'],
    subTitle: 'politics',
    chooseOption: ''
  },
  {
    title: '历史',
    enTitle: 'Historical achieveme',
    options: ['A', 'B', 'C', 'D', 'E'],
    subTitle: 'history',
    chooseOption: ''
  },
  {
    title: '地理',
    enTitle: 'Geographical achieve',
    options: ['A', 'B', 'C', 'D', 'E'],
    subTitle: 'geography',
    chooseOption: ''
  },
  {
    title: '物理',
    enTitle: 'Physical performance',
    options: ['A', 'B', 'C', 'D', 'E'],
    subTitle: 'physics',
    chooseOption: ''
  },
  {
    title: '化学',
    enTitle: 'Chemistry achievemen',
    options: ['A', 'B', 'C', 'D', 'E'],
    subTitle: 'chemical',
    chooseOption: ''
  },
  {
    title: '生物',
    enTitle: 'Biological achieveme',
    options: ['A', 'B', 'C', 'D', 'E'],
    subTitle: 'biology',
    chooseOption: ''
  },
  {
    title: '技术',
    enTitle: 'Technical achievemen',
    options: ['A', 'B', 'C', 'D', 'E'],
    subTitle: 'technology',
    chooseOption: ''
  }
]);
import { Notify } from 'vant';
import 'vant/es/notify/style';
const route = useRoute();
const router = useRouter();
const currentItems = ref([]);
const show = ref(true);

//点击立即开始时判断是否登录，未登跳转登录,这需要走接口，目前先写弹窗了
const begin = () => {
  // token是否存在
  console.log(sessionStorage.getItem('PHONE-TOKEN'));
  if (sessionStorage.getItem('PHONE-TOKEN')) {
    show.value = false;
  } else {
    router.push({ path: '/login', query: { path: '/smartRegistration' } });
  }
};

const goToRecord = () => {
  if (sessionStorage.getItem('PHONE-TOKEN')) {
    router.push({ path: '/history' });
  } else {
    router.push({ path: '/login', query: { path: '/smartRegistration' } });
  }
};

const closeModal = () => {
  show.value = false;
};
const changeOptions = (index1, project) => {
  if (sessionStorage.getItem('PHONE-TOKEN')) {
    smartRegistration[index1].chooseOption = project;
  } else {
    router.push({ path: '/login', query: { path: '/smartRegistration' } });
  }
};

const submit = () => {
  if (sessionStorage.getItem('PHONE-TOKEN')) {
    for (let i = 0; i < smartRegistration.length; i++) {
      if (smartRegistration[i].chooseOption == '') {
        Notify({
          type: 'warning',
          message: `请选择「${smartRegistration[i].title}」考试成绩`
        });
        return;
      }
    }
    if (currentItems.value.length < 3) {
      Notify({ type: 'warning', message: `请选择3项` });
      return false;
    }
    let options = {};
    smartRegistration.map((item, index) => {
      options[item.subTitle] = item.chooseOption.toLowerCase();
    });
    getIntelligent({
      token: sessionStorage.getItem('PHONE-TOKEN'),
      suject_one: currentItems.value[0],
      suject_two: currentItems.value[1],
      suject_three: currentItems.value[2],
      ...options
    }).then((res) => {
      console.log(res.result);
      router.push({
        path: '/list',
        query: { list: encodeURIComponent(JSON.stringify(res.result)) }
      });
    });
  } else {
    router.push({ path: '/login', query: { path: '/smartRegistration' } });
  }
};
const changeProject = (item) => {
  if (sessionStorage.getItem('PHONE-TOKEN')) {
    // 判断当前选中数组中是否包含,如果包含了则删除
    if (currentItems.value.includes(item)) {
      currentItems.value.splice(currentItems.value.indexOf(item), 1);
      projects.map((item1, index1) => {
        if (item == item1.name) {
          item1.active = false;
        }
      });
    } else {
      if (currentItems.value.length < 3) {
        currentItems.value.push(item);
      } else {
        Notify({ type: 'warning', message: '最多选择3项' });
      }
    }
    currentItems.value.map((item, index) => {
      projects.map((item1, index1) => {
        if (item == item1.name) {
          item1.active = true;
        }
      });
    });
  } else {
    router.push({ path: '/login', query: { path: '/smartRegistration' } });
  }
};
</script>

<style lang="less" scoped>
.smartRegistration {
  background-image: url('../../assets/images/smartRegistration-bg.png');
  background-size: 100%;
  background-repeat: no-repeat;
  position: relative;

  .active {
    background: #cacdfe !important;
    color: #fff;
  }
  .smartRegistration-record {
    position: absolute;
    right: 24px;
    top: 20px;
    font-size: 14px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #333333;
    line-height: 37px;
    z-index: 1000;
  }
  .smartRegistration-title {
    padding: 0 18px;
    font-size: 21px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #000493;
    line-height: 29px;
    letter-spacing: 1px;
    padding-top: 137px;
    margin-bottom: 4px;
  }

  .smartRegistration-subtitle {
    padding: 0 18px;
    font-size: 14px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #4347d3;
    line-height: 20px;
    letter-spacing: 4px;
    margin-bottom: 46px;
  }

  .smartRegistration-wrap-title {
    padding: 0 18px;
    display: flex;
    align-items: center;

    span {
      width: 3px;
      height: 17px;
      background: #8487e3;
      border-radius: 2px;
      margin-right: 3px;
    }

    font-size: 16px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #000000;
    line-height: 22px;
    letter-spacing: 4px;
    margin-bottom: 16px;
  }

  .schools-wrap {
    padding: 0 18px;
  }

  .smartRegistration-tects {
    padding: 0 20px;
    display: grid;
    grid-template-columns: 90px 90px 90px;
    grid-template-rows: 49px 49px 49px;
    grid-row-gap: 10px;
    grid-column-gap: 50px;

    .smartRegistration-tects-items {
      width: 90px;
      height: 39px;
      background: #ffffff;
      border-radius: 3px;
      border: 1px solid #8c73ff;
      font-size: 18px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #7456ff;
      line-height: 25px;
      text-align: center;
      line-height: 39px;
    }
  }

  .btn {
    width: 172px;
    height: 45px;
    background: linear-gradient(360deg, #4449ff 0%, #e1e2f8 100%);
    box-shadow: 0px 1px 5px 0px rgba(161, 146, 213, 0.58),
      inset 0px 0px 3px 0px rgba(255, 255, 255, 0.72);
    border-radius: 23px;
    font-size: 18px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #ffffff;
    letter-spacing: 2px;
    text-align: center;
    margin: 0 auto;
    margin-bottom: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

.smartRegistration {
  .smartRegistration-wrap-item {
    padding: 0 12px;
    display: flex;
    align-items: center;
    margin-bottom: 11px;
    display: grid;
    grid-template-columns: auto 1fr;

    .smartRegistration-wrap-item-left {
      position: relative;
      border-right: 1px solid #8c73ff;
      display: flex;
      flex-direction: column;
      align-items: flex-end;
      padding-right: 5px;
      width: 130px;

      .img {
        position: absolute;
        left: 0;
        top: 0;
        width: 70px;
        height: 54px;
      }

      .title {
        font-size: 18px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #000000;
        line-height: 25px;
        letter-spacing: 5px;
        margin-bottom: 6px;
        margin-top: 20px;
      }

      .subtitle {
        font-size: 11px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #c6c3ff;
        line-height: 16px;
        white-space: nowrap;
      }
    }

    .smartRegistration-wrap-item-right {
      display: flex;
      flex-wrap: wrap;
      position: relative;
      flex-grow: 1;
      img {
        position: absolute;
        right: 0;
        bottom: 0;
        z-index: -1;
      }
      .content-wrap {
        padding: 0 0 0 18px;
        display: flex;
        flex-wrap: wrap;
      }

      .content {
        width: 64px;
        height: 23px;
        background: transparent;
        border-radius: 2px;
        border: 1px solid #8c73ff;
        font-size: 12px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #7456ff;
        line-height: 23px;
        margin-right: 10px;
        margin-bottom: 11px;
        text-align: center;
      }
    }
  }
}

.joinNow {
  width: 100vw;
  height: 132vh;
  background: rgba(17, 17, 17, 0.75);

  .btn {
    width: 172px;
    height: 45px;
    background: linear-gradient(360deg, #4449ff 0%, #e1e2f8 100%);
    box-shadow: 0px 2px 5px 0px rgba(126, 113, 169, 0.58),
      inset 0px 0px 3px 0px rgba(255, 255, 255, 0.72);
    border-radius: 23px;
    font-size: 18px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #ffffff;
    line-height: 25px;
    letter-spacing: 2px;
    margin-top: 45px;
  }
  .close {
    background-image: url(/src/assets/images/close.png);
    background-size: 100% 100%;
    background-repeat: no-repeat;
    position: absolute;
    top: 27%;
    right: 34px;
    width: 20px;
    height: 20px;
  }

  .join {
    background-image: url(/src/assets/images/join.png);
    background-size: 100% 100%;
    background-repeat: no-repeat;
    z-index: 999;
    position: absolute;
    top: 30%;
    left: 34px;
    width: 346px;
    height: 460px;

    span {
      display: inline-block;
      padding: 7px 28px;
      font-size: 16px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #333333;
      line-height: 20px;

      &:first-child {
        margin-top: 80px;
      }
    }
  }
}
</style>
